package com.steven.io;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.OutputStream;

public class FileSearchDemo {
	public static void main(String[] args) throws Exception {
		
		File file = new File("F:\\");
		File f = new File("log.txt");
		BufferedWriter bw = new BufferedWriter(new FileWriter(f));
		showFiles(file,0,bw);
		System.out.println("over");
		 bw.close();
		
	}
	private static String getLevel(int level){
		StringBuilder sb = new StringBuilder();
		sb.append("|--");
		for(int i=0;i<level;i++){
			sb.insert(0, "|  ");
			
		}
		return sb.toString();
	}
	private static void showFiles(File file,int level,BufferedWriter bw) throws Exception {
		 
		File[] names = file.listFiles();
	
		
	
		bw.write(getLevel(level)+file);
		bw.newLine();
//		System.out.println(getLevel(level)+file);
	 
		level++;
		
	 
		for(File name:names){
			
			if(name.isFile()){
			 
				bw.write(getLevel(level)+name);
				bw.newLine();
			//					System.out.println(getLevel(level)+name);
			
				
			}else{
			 
			showFiles(name,level,bw);
			}
	
		}
	
	}
	

}
